package GameMain.View.GameCenter
{
	import Engine.AIUGame.AIGDate;
	import Engine.AIUGame.AIGame;
	import Engine.AIUGame.AIGroup;
	import Engine.AIUGame.AIPoint;
	import Engine.AIUGame.AISprite;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.LoaderInfo;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import library.Function.GlobalFun;
	

	public class PlayerModel extends AISprite
	{
		
		public static var PlayerBit:BitmapData = null;
		
		private static const MAX_velocityX:int = 200;  //左右的移动速度
		private static const MAX_velocityY:int = 500;
		
		
		
		public static function setGameSource(info:LoaderInfo):void
		{
			var _class:Class = info.applicationDomain.getDefinition("Fla.Bit.PlayerAction") as Class;
			PlayerBit = (new _class) as BitmapData;
			
			
			_class = info.applicationDomain.getDefinition("Fla.Bit.BulletBit") as Class;
			Bullet.BulletBit = (new _class) as BitmapData;
			
			_class = info.applicationDomain.getDefinition("Fla.Bit.NPCBit") as Class;
			NPC.NPCBit = (new _class) as BitmapData;
			
		}
		
		
		public function PlayerModel()
		{
			super();
			loadGraphic(PlayerBit,true,true,60,94);
			addAnimation("stand",[0,1,2,3],6);
			addAnimation("walk",[4,5,6,7],6);
			acceleration.y = 600;
			
			y = 0;
			x = 80;
		}
		
		override public function update():void
		{
			velocity.x = 0;
			if(AIGDate.keys.D)
			{
				velocity.x = MAX_velocityX;
				facing = AISprite.RIGHT;
			}
			else if(AIGDate.keys.A)
			{
				velocity.x = -MAX_velocityX;
				facing = AISprite.LEFT;
			}
			
			if(velocity.y == 0 && AIGDate.keys.justPressed("K"))
			{
				velocity.y = -400;
			}
			
			if(velocity.x == 0 && velocity.y == 0)
			{
				play("stand");
			}
			else
			{
				play("walk");
			}
			
			
			super.update();
		}
	}
}